var FeedCache = function(max){
	
	var cache = {};
	var size = 0;
	var maxSize = max || 100;
	var resizing = false;

	this.factory = function(){
		
		this.get = function(key){
		
			var entry = cache[key];
			var x = 0
			while(entry && !entry.ready && x < 3){
				java.lang.Thread.sleep(1000);
				x++;
			}
			if(!resizing && entry && ((new Date()).getTime() > entry.date.getTime())){
				entry.stale = true;
			}
			return entry;	
		}
		
		this.add = function(key, entry){
			
			if(size > maxSize && !resizing){
				resizing = true;
				var savedEntry;
				var keyToDelete;
				$.each(cache, function(key, entry){
					if(!savedEntry || entry.date.getTime() < savedEntry.date.getTime()){
						savedEntry = entry;
						keyToDelete = key;
					}
				});
				delete cache[key];
				size--;
				resizing = false;
			}
			entry.date = (new Date()).addSeconds(60);
			cache[key] = entry;
			size++;
		}
		
		
	}
	
}
